<?php
/**
 * @特惠赚、提现控制器
 * Author: 小谢     
 * Date: 2019/05/20
 */
namespace app\admin\controller;
use think\facade\Session;
use think\facade\View;
use think\Db;

class Withdraw extends Base {
  
    /**
    * 提现列表
     */
    public function lists() {
        $start_time  = strtotime(I('start_time'));
        $end_time    = strtotime(I('end_time'));
        $keyword     = I('keyword');
        $status      = I('status');//状态

        $where = '';
        if (!empty($start_time) && !empty($end_time)) {
            $where = " create_time >= ".$start_time." AND ". " create_time <=".$end_time;
        }

        if (!empty($where) && $keyword && $status) {
             $where.= ' AND user_id LIKE '.'"%'.$keyword.'%"'.' AND status='.$status;
        } else if (!empty($where) && $keyword) {
             $where.= ' AND user_id LIKE '.'"%'.$keyword.'%"';
        } else if(!empty($where) && $status) {
             $where.= ' AND status='.$status;
        }else if($status == 0) {
             $where.= ' AND status='.$status ? $status : 0;
        } else {
             $where = "1=1";
        }

        $p = I('p/d',1);
        $list = M('withdrawals')->where($where)->order('id ASC')->page($p.',20')->paginate(20);
        $count = $list->count();
        View::share([
            'list'=>$list,
            'count'=>$count,
            "stime"=>time(),
            'etime'=>time()+3600*24 *365,
        ]);
        return View();
    }

    /**
     * [del 删除操作]
     */
    public function del(){
        $data = I('post.');
        if($data['id'] > 0 ){
            $res = M('withdrawals')->where('id', $data['id'])->delete();
            if($res){
                $this->ajaxReturn(['status'=>1,'msg'=>"操作成功",'url'=>U('Admin/withdraw/lists')]);
            }else{
                $this->ajaxReturn(['status'=>-1,'msg'=>"操作失败"]);
            }
        }
    }

    /**
     * 查看提现信息
     */
    public function info() {
        $id = I('get.id');
        if($id) {
            $info = M('withdrawals')->alias('w')->join('__USER__ u','w.user_id = u.user_id')->where(['w.id'=>$id])->find();
            View::share(['info'=>$info]);
        }
        return View();
    }

    /**
     * 提现审核操作
     */
    public function handle() {
          $data = I('post.');
          if($data['id']) {
              $res = M('withdrawals')->where(['id'=>$data['id']])->update($data);
          }
          if($res) {
                $this->ajaxReturn(['status'=>1]);
          }
          $this->ajaxReturn(['status'=>0]);
    }

}